package com.boot.mall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.boot.mall.product.vo.AttrGroupWithAttrsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.boot.mall.product.entity.AttrGroupEntity;
import com.boot.mall.product.service.AttrGroupService;
import com.boot.common.utils.PageUtils;
import com.boot.common.utils.R;



/**
 * 属性分组
 *
 * @author huihui
 * @email 2565036109@qq.com
 * @date 2021-05-06 14:41:26
 */
@RestController
@RequestMapping("product/attrgroup")
public class AttrGroupController {
    @Autowired
    private AttrGroupService attrGroupService;

    /**
     * 根据三级分类id条件查询分组列表
     */
    @RequestMapping("/list/{categoryId}")
    public R list(@RequestParam Map<String, Object> params,@PathVariable("categoryId") Long categoryId){
        PageUtils page = attrGroupService.pageQuery(params,categoryId);
        return R.ok().put("page",page);
    }

    /**
     * 根据分类id查询分页分组属性信息
     */
    @GetMapping("/{categoryId}/withattr")
    public R getAttrGroupWithAttrs(@PathVariable String categoryId){
        List<AttrGroupWithAttrsVo> attrsVos = attrGroupService.getAttrGroupWithAttrsByCatId(categoryId);
        return R.ok().put("data",attrsVos);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrGroupId}")
    public R info(@PathVariable("attrGroupId") String attrGroupId){
		AttrGroupEntity attrGroup = attrGroupService.getAttrGroupById(attrGroupId);
        return R.ok().put("attrGroup", attrGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.save(attrGroup);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.updateById(attrGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrGroupIds){
		attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return R.ok();
    }

}
